-- NewTeamBeInvitedView

local NewTeamMemberHeadRender = import(".renders.NewTeamMemberHeadRender")
local TeamModel = app:getInst("TeamModel") -- 此处虽然包含了 TeamModel 但是只调用了其静态成员函数

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.NewTeamBeInvitedView

function ClassRef:init( data )
    display.nodeRemoveForNotHit( self._ui["Panel"], function()
            executeFunc(self._onCloseView, self)
        end )

    self._ui["Panel/Button_queding"]:addClickEventListener(function()
        executeFunc(self._onOperate, "BeInvited_sure", self._data)
        executeFunc(self._onCloseView)
    end)
    self._ui["Panel/Button_quxiao"]:addClickEventListener(function()
        executeFunc(self._onOperate, "BeInvited_cancel", self._data)
        executeFunc(self._onCloseView)
    end)

    self._InviterHeadIcon = NewTeamMemberHeadRender.create(self._ui["Panel/head"])
    self._InviterHeadIcon:onClick(function(sender)
            local size = sender:getContentSize()
            local pos = sender:convertToWorldSpace(cc.p(size.width, size.height/2))
            UIHandler:showHeadMenu({online=true, attr=self._data.dataTemp.inviterInfo, pos=pos})
        end)
end

-- 接到邀请
-- params = {
--  remindId = 100411,
--  dataTemp = InviteInfo pb结构
--  teamTarget = TeamTargetVo／nil
-- }
function ClassRef:refreshContent( params )
    self._data = params
    local data = params.dataTemp

    -- 队伍目标展示
    local teamTarget = params.teamTarget
    self._ui.target:setVisible(teamTarget ~= nil)
    if teamTarget then
        self._ui.target:setString(string.format(L("lua_code_text_149"), teamTarget:getFullName()))
    end

    self._InviterHeadIcon:setData( data.inviterInfo )
    local curMemberNum = 1
    local inviterTeamGrade = L("lua_code_text_67")
    local memberNumMax = TeamModel:getMaxNumOfMembersByTeamGarde( 0 )
    local totalCombatPower = 0

    if data.teamInfo then
        curMemberNum = #data.teamInfo.teamMembers
        for i, member in ipairs( data.teamInfo.teamMembers ) do
            totalCombatPower = totalCombatPower + member.userBaseInfo.combatPower
        end
        local teamType = protobuf.enum_id("pb_team.TeamInfo_Type", data.teamInfo.type)
        memberNumMax = TeamModel:getMaxNumOfMembersByTeamGarde( teamType )
        if 1 == teamType then -- 军团？
            inviterTeamGrade = L("lua_code_text_43")
        end
    else
        totalCombatPower = data.inviterInfo.combatPower
    end

    -- 邀请人信息
    self._ui["Panel/tips"]:setString( string.format( L("lua_code_text_346"), data.inviterInfo.name, inviterTeamGrade) )
    -- 成员个数
    self._ui["Panel/num"]:setString( string.format( L("lua_code_text_38"), ( curMemberNum .. "/" .. memberNumMax ) ) )
    -- 战斗力
    self._ui["Panel/combat"]:setString( string.format( L("lua_code_text_185"), totalCombatPower ) )
end

return ClassRef
